package com.julis.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.julis.R;
import com.julis.base.BaseApplication;
import com.julis.base.Base_Z_Adapter;


public class DOWN_Adapter extends Base_Z_Adapter {
    Activity activity;

    public void addActivity(Activity activity) {
        this.activity = activity;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DOWN_Adapter.Holder holder = null;
        // 查找控件
        if (null == convertView) {
            convertView = LayoutInflater.from(BaseApplication.getInstance())
                    .inflate(R.layout.item_list, null);
            holder = new DOWN_Adapter.Holder();

            holder.tv_index = (TextView) convertView
                    .findViewById(R.id.tv_index);
            holder.tv_message = (TextView) convertView
                    .findViewById(R.id.tv_message);

            // 缓存Holder
            convertView.setTag(holder);
        } else {
            holder = (DOWN_Adapter.Holder) convertView.getTag();
        }
        String entity = (String) getItem(position);
        String index = entity.substring(0, entity.indexOf("："));
        String message = entity.substring(entity.indexOf("：") + 1);
        holder.tv_index.setText(index);
        holder.tv_message.setText(message);
        if (message.equals("成功")) {
            holder.tv_message.setTextColor(activity.getResources().getColor(R.color.ym_green));
        } else {
            holder.tv_message.setTextColor(activity.getResources().getColor(R.color.red));
        }



        return convertView;
    }

    public class Holder {


        TextView tv_index;
        TextView tv_message;
    }
}
